@{
Layout = "_LayoutAndSidebar";
}

<style>
    .page {
        height: 100%;
        overflow: auto;
        margin-bottom: unset !important;
        box-sizing: border-box;
    }
</style>

<div class="box page">
    <h3 class="title is-5">创建货源信息</h3>
    <div class="field is-horizontal">
        <div class="field-label is-normal">
            <label class="label">基本信息</label>
        </div>
        <div class="field-body">
            <div class="field">
                <p class="control is-expanded has-icons-left">
                    <input class="input" type="text" placeholder="姓名" id="input_name">
                    <span class="icon is-small is-left">
                        <i class="fas fa-user"></i>
                    </span>
                </p>
            </div>
            <div class="field">
                <p class="control is-expanded has-icons-left has-icons-right">
                    <input class="input" type="tel" placeholder="手机号" id="input_phonenumber">
                    <span class="icon is-small is-left">
                        <i class="fas fa-phone"></i>
                    </span>
                </p>
            </div>
        </div>
    </div>

    <div class="field is-horizontal">
        <div class="field-label"></div>
        <div class="field-body">
            <div class="field is-expanded">
                <div class="field has-addons">
                    <p class="control">
                        <a class="button is-static">
                            中国/
                        </a>
                    </p>
                    <p class="control is-expanded">
                        <input class="input" type="text" placeholder="详细地址" id="input_address">
                    </p>
                </div>
                <p class="help">请详细填写省市区以及具体位置信息</p>
            </div>
        </div>
    </div>

    <div class="field is-horizontal">
        <div class="field-label">
            <!-- Left empty for spacing -->
        </div>
        <div class="field-body">
            <div class="field">
                <div class="control">
                    <button class="button is-primary" id="button_submit">
                        确认创建
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    let E_input_name = document.getElementById("input_name");
    let E_input_phonenumber = document.getElementById("input_phonenumber");
    let E_input_address = document.getElementById("input_address");

    let E_button_submit = document.getElementById("button_submit");

    E_button_submit.onclick = function () {
        let data = {
            ChargeName: E_input_name.value,
            ChargePhoneNumber: E_input_phonenumber.value,
            Address: E_input_address.value,
        };

        E_button_submit.classList.add("is-loading");
        $.ajax({
            type: "POST",
            url: "/Work/CreateSupplier",
            data: data,
            success: function (data) {
                if (data.code == 0) {
                    alert("创建成功");
                    window.location.href = "/Work/SupplierList";
                } else {
                    alert(data.message);
                }
            },
            failure: function (errMsg) {
                alert(errMsg);
            },
            complete: function () {
                E_button_submit.classList.remove("is-loading");
            }
        });
    }

</script>